package cc.io24.knewcafe.boss.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update sys_permission set is_deleted = 1 where id = ?")
@Where(clause = "is_deleted = 0")
@org.hibernate.annotations  .Table(appliesTo = "sys_permission",comment="系统权限表")
public class SysPermission implements Serializable {

    @Id
    @GeneratedValue(generator = "uuid4i")
    @GenericGenerator(name = "uuid4i", strategy = "uuid2")
    @Column(name="id",columnDefinition = "varchar(64) not null comment 'id'")
    private String id ;

    @Column(name="menu_code",columnDefinition = "varchar(64) comment '归属菜单,前端判断并展示菜单使用'")
    private String menuCode ;

    @Column(name="menu_name",columnDefinition = "varchar(64)  comment '菜单的中文释义'")
    private String menuName ;

    @Column(name="permission_code",columnDefinition = "varchar(64) not null comment '权限的代码/通配符,对应代码中@RequiresPermissions 的value'")
    private String permissionCode ;

    @Column(name="permission_name",columnDefinition = "varchar(64)  comment '本权限的中文释义'")
    private String permissionName ;

    @Column(name="required_permission",columnDefinition = "tinyint(1) DEFAULT '2' COMMENT '是否本菜单必选权限, 1.必选 2非必选 通常是\"列表\"权限是必选'")
    private Integer requiredPermission ;

    @JsonIgnore
    @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    private Set<SysRole> roles;


    @Column(name = "is_deleted")
    private Integer isDeleted = 0;

    @CreatedDate
    @Column(name = "create_date")
    private Date createDate;

    @LastModifiedDate
    @Column(name = "lastModified_date")
    private Date lastModifiedDate;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMenuCode() {
        return menuCode;
    }

    public void setMenuCode(String menuCode) {
        this.menuCode = menuCode;
    }

    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    public String getPermissionCode() {
        return permissionCode;
    }

    public void setPermissionCode(String permissionCode) {
        this.permissionCode = permissionCode;
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }

    public Integer getRequiredPermission() {
        return requiredPermission;
    }

    public void setRequiredPermission(Integer requiredPermission) {
        this.requiredPermission = requiredPermission;
    }

    public Set<SysRole> getRoles() {
        return roles;
    }

    public void setRoles(Set<SysRole> roles) {
        this.roles = roles;
    }

    public Integer getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Integer isDeleted) {
        this.isDeleted = isDeleted;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getLastModifiedDate() {
        return lastModifiedDate;
    }

    public void setLastModifiedDate(Date lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }
}
